import type {ExtractPropTypes, PropType} from 'vue'
import {buildProps, type DevMethods} from "@/utils";

export const devDownloadProps = buildProps({
    // 下载方式
    type: {
        type: String as PropType<'file' | 'blob' | 'image'>,
        default: 'file'
    },
    // 下载地址
    url: {
        type: String,
        default: ''
    },
    // 是否使用接口
    useApi: {
        type: Boolean,
        default: false
    },
    // 绑定的数据
    devDownloadFieldsFn: {
        type: Function as PropType<DevMethods['devDownloadFieldsFn']>,
    },
    // 接口
    api: {
        type: Function as PropType<(condition?: Record<string, any>) => Promise<any>>,
        default: () => {
        }
    },
    // 下载结果名称
    name: {
        type: String
    },
    buttonContent:{
        type: String,
        default:'下载'
    },
    // 接口下载携带的参数
    apiParams: {
        type: Object as PropType<any>,
        default: () => {
            return {};
        }
    },
    // 下载的文件类型
    fileType: {
        type: String
    },
    // 下载的图片类型
    imageType: {
        type: String,
        default: 'image/png'
    },
    blobOptions: {
        type: Object as PropType<any>,
        default: () => {
            return {type: 'application/vnd.ms-excel'};
        }
    },
    // 是否禁用
    disabled: {
        type: Boolean,
        default: false
    },
    // 是否隐藏按钮
    hideButton: {
        type: Boolean,
        default: false
    },
    buttonLink: {
        type: Boolean,
        default: true
    },
    buttonType: {
        type: String as PropType<'primary' | 'success' | 'warning' | 'danger' | 'info' | 'default'>,
        default: 'primary'
    },
    // image下载时是否允许降级处理
    allowFallback:{
        type: Boolean,
        default: true
    }
} as const)
export type DevDownloadProps = ExtractPropTypes<typeof devDownloadProps>
